package cn.itsource.ymcc.consumer;

import cn.itsource.ymcc.common.constant.Constants;
import cn.itsource.ymcc.common.constant.RocketConstants;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

@Component
@RocketMQMessageListener(consumerGroup = "service-common-SMSmessage-consumer",
        //Topic
        topic = RocketConstants.COURSE_SEND_SMS_TOPIC,
        //TAGS
        selectorExpression = RocketConstants.COURSE_SEND_SMS_TAG
)
public class CourseSendSMSConsumer implements RocketMQListener<MessageExt> {
    @Override
    public void onMessage(MessageExt messageExt) {
        try {
            byte[] body = messageExt.getBody();
            String string = new String(body, Constants.UTF8);
            JSONObject jsonObject = JSON.parseObject(string);
            //给那个用户发消息
            Object o = jsonObject.get("userId");
            Object o1 = jsonObject.get("content");
            //调用工具类 发送短信
            System.out.println("短信："+o.toString() + ":" + o1);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
}
